<%-- 
    Document   : goods1
    Created on : Oct 26, 2011, 7:18:58 PM
    Author     : X@KER
--%>

<%@page import="java.util.Collection"%>
<%@page import="java.util.Iterator"%>
<%@page import="javax.rmi.PortableRemoteObject"%>
<%@page import="manufacturerBean.ManufacturerHome"%>
<%@page import="manufacturerBean.Manufacturer"%>
<%@page import="categorybean.Category"%>
<%@page import="categorybean.CategoryHome"%>
<%@page import="GoodsBean.Goods"%>
<%@page import="GoodsBean.GoodsHome"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.HashMap"%>
<%@page import="DBConnection.ATeamObject"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><%=request.getParameter("goodName")%></title>
        <%  InitialContext initialContext;
            GoodsHome goodsHome;
            Goods goods;
            Object homeObject;

            CategoryHome categoryHome;
            Category category;
            Object homeObject1;

            Manufacturer manufacturer;
            ManufacturerHome manufacturerHome;
            Object homeObject2;

            ATeamObject ato = new ATeamObject();

            try {
                initialContext = new InitialContext();
                homeObject = initialContext.lookup("GoodsBean");
                goodsHome = (GoodsHome) PortableRemoteObject.narrow(homeObject,
                        GoodsHome.class);

                homeObject1 = initialContext.lookup("CategoryBean");
                categoryHome = (CategoryHome) PortableRemoteObject.narrow(homeObject1,
                        CategoryHome.class);

                homeObject2 = initialContext.lookup("ManufacturerBean");
                manufacturerHome = (ManufacturerHome) PortableRemoteObject.narrow(homeObject2,
                        ManufacturerHome.class);
        %>
    </head>
    <body background="1.jpg" bgproperties="fixed">
        <h4><a href="index.jsp">Главная</a></h4>
        <a href="Manufacturers.jsp">Каталог товаров</a>>
        <a href="GoodsByManufacturer.jsp?manName=<%=request.getParameter("manName")%>&manID=<%=request.getParameter("manID")%>"><%=request.getParameter("manName")%></a>>
        <a href="goods1.jsp?manID=<%=request.getParameter("manID")%>&manName=<%=request.getParameter("manName")%>&goodID=<%=request.getParameter("goodID")%>&goodName=<%=request.getParameter("goodName")%>"><%=request.getParameter("goodName")%></a>
        <table>
            <tr>
                <td>
                    <form name="MainPageForm" method="post" action="findResults.jsp">
                        <center>
                            <h2>Поиск товаров</h2>
                            <table>
                                <tr>
                                    <td>
                                        <b>Наименование товара</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="text" name="GoodsName" size="50">
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="radio" name="SearchingCriteria" value="0" checked="true"> Совпадает
                                    </td>
                                </tr>
                                <tr>
                                    <td> 
                                        <input type="radio" name="SearchingCriteria" value="1"> Содержит
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <b>Цена товара</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="text" name="GoodsPriceFrom" size="10">
                                        <input type="text" name="GoodsPriceTo" size="10" id="txt">
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="radio" name="GoodsPriceOptions" value=">" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Больше чем<br>
                                        <input type="radio" name="GoodsPriceOptions" value="<" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Меньше чем<br>
                                        <input type="radio" name="GoodsPriceOptions" value="=" checked="true" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Равно значению<br>
                                        <input type="radio" name="GoodsPriceOptions" value="BETWEEN" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Лежит в диапазоне<br>
                                    </td>
                                </tr>
                                <tr>
                                    <td><b>Производитель</b><td>
                                </tr>
                                <%  Collection allManufacturer = manufacturerHome.findAll();
                                    Iterator iter = allManufacturer.iterator();
                                %>
                                <tr>
                                    <td>
                                        <select name="ManufacturerSelect">
                                            <option></option>
                                            <% while (iter.hasNext()) {
                                                    manufacturer = (Manufacturer) iter.next();
                                            %>
                                            <option value="<%= manufacturer.getObjectId()%>"><%= manufacturer.getName()%></option>
                                            <% }%>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td><b>Категория товара</b></td>
                                </tr>
                                <% Collection allCategory = categoryHome.findAll();
                                    iter = allCategory.iterator();
                                %>
                                <tr>
                                    <td>
                                        <select name="GoodsCategorySelect">
                                            <option></option>
                                            <% while (iter.hasNext()) {
                                                    category = (Category) iter.next();

                                            %>
                                            <option value="<%= category.getObjectId()%>"><%= category.getName()%></option>
                                            <% }%>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="submit" value="Поиск">
                                        <input type="reset" value="Очистить">
                                    </td>
                                </tr> 
                            </table>
                        </center>
                    </form>
                </td>
                <td valign="top">
                    <h1><%=request.getParameter("goodName")%></h1>
                    <%  goods = goodsHome.findByPrimaryKey(Integer.parseInt(request.getParameter("goodID")));
                    %>
                    <h3>
                        Описание
                    </h3>    
                    <%= goods.getGoodsDescription() %>
                    <h3>
                        Категория
                    </h3>    
                    <a href="goodsList.jsp?catID=<%= goods.getCategoryId() %>&catName=<%= goods.getNameOfCategory() %>"><%= goods.getNameOfCategory() %></a>
                    <h3>
                        Производитель
                    </h3>    
                    <a href="GoodsByManufacturer.jsp?manName=<%=request.getParameter("manName")%>&manID=<%=request.getParameter("manID")%>"><%=request.getParameter("manName")%></a>
                    <h3>
                        Цена
                    </h3>    
                    <%= goods.getPrice() %>
                    <h3>
                        Количество
                    </h3>    
                    <%= goods.getNumber() %>
                    <br>
                    <form name="deleteGoods" action="delGoods.jsp?name=<%=request.getParameter("goodID")%>"
                          method="POST">
                        <input type="submit" value="Удалить товар" name="delete" />
                    </form>
                    <form name="editGoods" action="editGoods.jsp?goodID=<%=request.getParameter("goodID")%>"
                          method="POST">
                        <input type="submit" value="Изменить характеристики товара" name="edit" />
                    </form>                               
                </td>
            </tr>
        </table>
        <% } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        %>
    </body>
</html>
